<?php
/**
 * Send mail template.
 * For example, I wrote a profile post to someone,
 * I will see an event on my history event, and the one 
 * who i wrote to will receive a email.
 * 
 * @author james
 *
 */
class EmailMessageTemplate {
	
	const TAG_SEND_USER = '#SEND_USER';
	const TAG_INVITATION_TITLE = '#INVITATION_TITLE';
	const TAG_INVITATION_URL = '#INVITATION_URL';
	const TAG_MESSAGE = '#MESSAGE';
	const TAG_PASSWORD_RESET_URL = "#PASSWORD_RESET_URL";
	
	public static $PROFILE_POST = '#SEND_USER在你的profile上留言';
	public static $USER_MESSAGE = '<strong>#SEND_USER</strong>给你发了一封站内信';
	public static $FRIEND_ADD_REQUEST = '#SEND_USER请求加你为好友, 等待确认';
	public static $INVITATION_COMMENT = '#SEND_USER在你的邀请#INVITATION_TITLE上留言"#MESSAGE"';
	public static $INVITATION_REPLY = '#SEND_USER回复了你的邀请#INVITATION_TITLE';
	public static $SEND_INVITATION = '您的朋友#SEND_USER发送了一个邀请给您<br /><p>查看 <a href="#INVITATION_URL">点击这里</a><br />';
	public static $ATTEND_INVITATION = '#SEND_USER请求加入你的邀请#INVITATION_TITLE, 等待批准.';
	public static $APPROVE_ATTEND_INVITATION = '#SEND_USER批准了你参加邀请#INVITATION_TITLE的请求,您将会收到一封新的邮件,包含邀您的请链接.';
	public static $PASSWORD_RESET_REQUEST = '点击下面的链接就可以重新设置您的密码<br/><a href="#PASSWORD_RESET_URL">重设密码</a>';
	
	/**
	 * Get message template, by given activity type.
	 * 
	 * @param $activityType
	 * @return return email message
	 */
	public static function getMessageTemplate($activityType) {
		$message = '';
		switch($activityType) {
			case Activity::INVITATION_CREATE:
				$message = self::$SEND_INVITATION;
				berak;
			case Activity::PROFILE_POST:
				$message = self::$PROFILE_POST;
				break;
			case Activity::USER_MESSAGE:
				$message = '';
				break;
			case Activity::FRIEND_ADD_REQUEST:
				$message = self::$FRIEND_ADD_REQUEST;
				break;
			case Activity::INVITATION_COMMENT:
				$message = self::$INVITATION_COMMENT;
				break;
			case Activity::INVITATION_REPLY:
				$message = self::$INVIATION_REPLY;
				break;
			case Activity::ATTEND_INVITATION_REQUEST:
				$message = self::$ATTEND_INVITATION;
				break;
			case Activity::APPROVE_ATTEND_REQUEST:
				$message = self::$APPROVE_ATTEND_INVITATION;
				break;
		}
		return $message;
	}
	
	/**
	 * Get email message depend on different acitivty type.
	 * 
	 * @param $activityType
	 * @param data array of values that to replace the tag
	 * @return return actual message need to be sent out
	 */
	public static function getMessage($activityType, $data) {
		$message = '';
		switch ($activityType) {
			case Activity::PROFILE_POST:
				$message = str_replace(self::TAG_SEND_USER, $data[self::TAG_SEND_USER], self::$PROFILE_POST);
				break;
			case Activity::FRIEND_ADD_REQUEST:
				$message = str_replace(self::TAG_SEND_USER, $data[self::TAG_SEND_USER], self::$FRIEND_ADD_REQUEST);
				break;
			case Activity::INVITATION_COMMENT:
				$message = str_replace(self::TAG_SEND_USER, $data[self::TAG_SEND_USER], self::$INVITATION_COMMENT);
				$message = str_replace(self::TAG_INVITATION_TITLE, $data[self::TAG_INVITATION_TITLE], $message);
				$message = str_replace(self::TAG_MESSAGE, $data[self::TAG_MESSAGE], $message);
				break;
			case Activity::INVITATION_CREATE:
				echo self::$SEND_INVITATION;
				$message = str_replace(self::TAG_SEND_USER, $data[self::TAG_SEND_USER], self::$SEND_INVITATION);
				$message = str_replace(self::TAG_INVITATION_URL, $data[self::TAG_INVITATION_URL], $message);
				break;
			case Activity::ATTEND_INVITATION_REQUEST:
				$message = str_replace(self::TAG_SEND_USER, $data[self::TAG_SEND_USER], self::$ATTEND_INVITATION);
				$message = str_replace(self::TAG_INVITATION_TITLE, $data[self::TAG_INVITATION_TITLE], $message);
				break;
			case Activity::APPROVE_ATTEND_REQUEST:
				$message = str_replace(self::TAG_SEND_USER, $data[self::TAG_SEND_USER], self::$APPROVE_ATTEND_INVITATION);
				$message = str_replace(self::TAG_INVITATION_TITLE, $data[self::TAG_INVITATION_TITLE], $message);
				break;
			case Activity::INVITATION_REPLY:
				$message = str_replace(self::TAG_SEND_USER, $data[self::TAG_SEND_USER], self::$INVITATION_REPLY);
				$message = str_replace(self::TAG_INVITATION_TITLE, $data[self::TAG_INVITATION_TITLE], $message);
				break;
			case Activity::USER_MESSAGE:
				$message = str_replace(self::TAG_SEND_USER, $data[self::TAG_SEND_USER], self::$USER_MESSAGE);
				break;
			case Activity::PASSWORD_RESET_REQUEST:
				$message = str_replace(self::TAG_PASSWORD_RESET_URL, $data[self::TAG_PASSWORD_RESET_URL], self::$PASSWORD_RESET_REQUEST);
				break;
		}
		return $message;
	}
}
?>